import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';

class AMUserInfoPage extends StatefulWidget {
  @override
  _AMUserInfoPageState createState() => _AMUserInfoPageState();
}

class _AMUserInfoPageState extends State<AMUserInfoPage> {
  @override
  Widget build(BuildContext context) {
    MediaQueryData mq = MediaQuery.of(context);
    final _bottomBarHeight = mq.padding.bottom;

    return Scaffold(
      appBar: AppBar(
        title: Text(
          "账户",
          style: TextStyle(color: Colors.black),
        ),
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(
          color: Colors.black, //change your color here
        ),
        elevation: 0,
      ),
      body: Container(
        height: double.infinity,
        color: Color(0xFFF0F0F0),
        child: Column(
          children: [
            _buildTips(),
            _buildItem("账户", "tom@test.com"),
            _buildItem("姓名", "Tom Teo"),
            Expanded(
                child: Container(
              alignment: Alignment.bottomCenter,
              child: GestureDetector(
                onTap: logoutAction,
                child: Container(
                  alignment: Alignment.center,
                  height: _bottomBarHeight + 35,
                  width: double.infinity,
                  color: Colors.white,
                  child: Text(
                    "注销登录",
                    style: TextStyle(fontSize: 18, color: Color(0xFF333333)),
                  ),
                ),
              ),
            ))
          ],
        ),
      ),
    );
  }

  _buildTips() {
    return Container(
      decoration: new BoxDecoration(
        //设置容器背景色
        color: Color(0xFFDEE5EE),
        //设置四周边框
        border: new Border.all(width: 1, color: Color(0x1A4A90E2)),
      ),
      height: 58.0,
      padding: EdgeInsets.fromLTRB(12, 10, 12, 10),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SvgPicture.asset("images/feedback.svg"),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: RichText(
                text: TextSpan(
                    text:
                        "你还可以通过PC浏览器访问Hik Connect Commercial，网址为：www.hik-connect/commeicial.com",
                    style: TextStyle(
                        wordSpacing: 1, fontSize: 12, color: Color(0xB3000000)),
                    children: [
                  TextSpan(
                    text: "  复制",
                    style: TextStyle(color: Color(0xFF455EEC)),
                    //可以点击访问链接 的文本
                    // recognizer: TapGestureRecognizer()
                    //   ..onTap = () async {
                    //     String url = "http://baidu.com";
                    //     if (await canLaunch(url)) {
                    //       await launch(url);
                    //     } else {
                    //       throw "error: $url";
                    //     }
                    //   })
                  )
                ])),
          )
        ],
      ),
    );
  }

  _buildItem(String title, String value) {
    return Container(
      color: Colors.white,
      height: 50,
      padding: EdgeInsets.fromLTRB(16, 10, 16, 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title,
            style: TextStyle(fontSize: 16),
          ),
          Text(
            value,
            style: TextStyle(fontSize: 12),
          )
        ],
      ),
    );
  }

  /// 退出登录
  void logoutAction() {
    //先删除本地用户信息
    //切换当前控制器
    print("退出登录逻辑");
  }
}
